import 'package:flutter/material.dart';
import '../demo/ui_demo.dart';
import '../demo/data_source/post.dart';

class MyDemo extends StatelessWidget implements Demo {
  MyDemo(this.title);
  @override
  String title;
  @override
  Widget build(BuildContext context) {
    return new HomePage(title: this.title,);
  }
}

class HomePage extends StatelessWidget {
  String title;
  HomePage({this.title});

  @override
  Widget build(BuildContext context) {
   return Scaffold(
      appBar: AppBar(
        title: Text(this.title),
        actions: <Widget>[
          IconSource("Card","13"),
        ],
      ),
      body: CardDemo(),
    );
  }
}

class CardDemo extends StatefulWidget {
  @override
  CardDemoState createState() => CardDemoState();
}

class CardDemoState extends State<CardDemo> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(8.0),
      child: ListView(
        children: posts.map((post){
          return Card(
            child: Column(
              children: <Widget>[
                AspectRatio(
                  aspectRatio: 16/9,
                  child: ClipRRect(
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(4.0),
                      topRight: Radius.circular(4.0),
                    ),
                    child: Image.network(post.imageUrl,fit: BoxFit.cover,),
                  ),
                ),
                ListTile(
                  title: Text(post.title),
                  subtitle: Text(post.author),
                  leading: CircleAvatar(
                    backgroundImage:NetworkImage(post.imageUrl) ,
                  ),
                ),
                Container(
                  padding: EdgeInsets.all(10),
                  child: Text(post.description),
                ),
                ButtonTheme.bar(
                  child: ButtonBar(
                    children: <Widget>[
                      FlatButton(
                        child: Text("LIKE"),
                        onPressed: (){},
                      ),
                      FlatButton(
                        child: Text("READ"),
                        onPressed: (){},
                      ),
                    ],
                  ),
                )
              ],
            ),
          );
        }).toList(),
      ),
    );
  }
}


